package com.dyz.leetcode._01_array;

public class _27_removeElement {
    public int removeElement(int[] nums, int val) {
        //双指针
        int n = nums.length;
        if(n==0){return n;}
        int start = 0;
        int end = 0;
        while(end<n){
            if(nums[end]!=val){
                nums[start]=nums[end];
                start++;
            }
            end++;
        }
        return start;
    }
    //双指针夹击
    public int removeElement1(int[] nums, int val) {
        int n = nums.length;
        if(n==0){return n;}
        int start = 0;
        int end = n-1;
        while (start<=end){
            if(nums[start]==val){
                nums[start] = nums[end];
                end--;
            }else {
                start++;
            }
        }
        return end+1;
    }

    public static void main(String[] args) {
        int [] nums = {3,2,2,3};
        new _27_removeElement().removeElement(nums, 3);
    }
}
